<template>
    <!-- 头部导航栏 -->
    <view class="navbar" :style="{ paddingTop: menu.top + 'px' }">
      <image src="http://xcxtp.njmswl.com/images/goBack.png" class="goBack" @tap="goBack" />
      <text class="title">购房资料包</text>
    </view>
    <scroll-view class="scroll-view" scroll-y>
      <!-- 新闻标题 -->
      <view class="newsTitle"> {{InformationList.title}} </view>
      <!-- 时间和浏览量 -->
      <view class="time">
        <span>{{InformationList.createTime}}</span>
        <span class="eyesImage">
          <image src="http://xcxtp.njmswl.com/images/eyes.png" class="eyes" />
        </span>
        <span>{{InformationList.count}}</span>
      </view>
      <!-- 文章内容 -->
      <view class="passage">
        <rich-text :nodes="InformationList.content"></rich-text>
      </view
      >
    </scroll-view>
</template>
<script setup>
import { ref, onMounted } from 'vue'
import { useRoute } from 'vue-router'
import { onLoad,onShareAppMessage,onShareTimeline } from '@dcloudio/uni-app'
import {getInformationAPI} from '../../services/information'
// 定义响应式数据
const menu = ref({})
const detailId = ref()
onLoad(async (options) => {
  detailId.value = options.id
  menu.value = uni.getMenuButtonBoundingClientRect()
  await getInformationList()
})
const InformationList = ref()
const getInformationList = async () => {
  const res = await getInformationAPI({ id: parseInt(detailId.value) })
  InformationList.value = res.data
}
// const title = ref('房价降价百万没人买!买不起，又卖出去怎么办? 该何去何从!')


// 方法定义
const goBack = () => {
  uni.navigateBack()
}

//uniapp微信小程序分享页面到微信好友

onShareAppMessage(() => {
});


//uniapp微信小程序分享页面到微信朋友圈

onShareTimeline(() => {
});
//-----token过期---------------------------------------------------------------------
const time = ref()
function myFunction() {
  time.value = uni.getStorageSync('expiresTime')||0
  // 获取当前系统时间的时间戳
  const currentTimeTimestamp = Date.now()
  
  // 检查Token是否过期
  if (time.value === 0) {
  } else if (currentTimeTimestamp >= time.value) {
    uni.showToast({
      title: '登录过期，请重新登录！',
      icon: 'none',
      duration: 2000,
      mask: true,
      success: function () {
        // 清理存储
        uni.removeStorageSync('accessToken')
        uni.removeStorageSync('appIdKey')
        uni.removeStorageSync('expiresTime')

        // 使用 setTimeout 来延迟跳转
        setTimeout(function () {
          uni.switchTab({
            url: '/pages/index/index',
          });
        }, 2000); // 等待2000毫秒（与 duration 相同）
      },
    })
  } else {
  }
}
const intervalId = setInterval(myFunction, 1000)
</script>
<style lang="less">
page {
  height: 100%;
  display: flex;
  flex-direction: column;
}
.scroll-view {
  flex: 1;
}
.navbar {
  margin-top: 8rpx;
  padding-bottom: 49rpx;
  background-color: #fff;
  background-size: cover;
  position: relative;
  display: flex;
  flex-direction: column;

  .goBack {
    position: absolute;
    width: 18rpx;
    height: 30rpx;
    margin-left: 56rpx;
    margin-top: 9rpx;
  }

  .title {
    text-align: center;
    font-family: PingFang SC;
    font-weight: 600;
    font-size: 36rpx;
    color: #000000;
  }
}

.newsTitle {
  font-family: PingFang SC;
  font-weight: 600;
  font-size: 34rpx;
  color: #000000;
  line-height: 48rpx;
  padding-left: 29rpx;
  padding-right: 20rpx;
}

.passage {
  padding:0 29rpx;
}

.time {
  font-size: 22rpx;
  color: #687a8c;
  padding-top: 22rpx;
  padding-left: 28rpx;
  padding-bottom: 60rpx;
  .eyesImage {
    margin-left: 37rpx;
  }
}

.eyes {
  width: 23rpx;
  height: 17rpx;
  color: #687a8c;
  object-fit: none;
}
</style>
